package edu.uclm.esi.tysweb.ajedrez.actions;

import java.util.Random;

import javax.mail.MessagingException;

import com.opensymphony.xwork2.ActionSupport;

public class RecuperarPwd extends ActionSupport {
	private String email;
	private Exception exception;
	
	public String execute() {
		try {
			EMailSenderService server=new EMailSenderService();
			long codigo=new Random().nextLong();
			server.enviarPorGmail(this.email, codigo);
			// TODO: guardar código en el servidor.
			return SUCCESS;
		} catch (MessagingException e) {
			this.exception=e;
			return ERROR;
		}
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getResultado() {
		if (exception!=null)
			return exception.toString();
		return "OK";
	}

}
